package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.WcsPowerExport;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WcsPower;
import com.ruoyi.system.service.IWcsPowerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电能统计Controller
 * 
 * @author ZYT
 * @date 2021-06-12
 */
@RestController
@RequestMapping("/system/power")
public class WcsPowerController extends BaseController
{
    @Autowired
    private IWcsPowerService wcsPowerService;

    /**
     * 查询电能统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:power:list')")
    @GetMapping("/list")
    public TableDataInfo list(WcsPower wcsPower)
    {
        startPage();
        List<WcsPower> list = wcsPowerService.selectWcsPowerList(wcsPower);
        return getDataTable(list);
    }

    /**
     * 导出电能统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:power:export')")
    @Log(title = "电能统计", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WcsPower wcsPower)
    {
        List<WcsPowerExport> list = wcsPowerService.exportWcsPowerList(wcsPower);
        ExcelUtil<WcsPowerExport> util = new ExcelUtil<WcsPowerExport>(WcsPowerExport.class);
        return util.exportExcel(list, "用电量统计");
    }

    /**
     * 获取电能统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:power:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wcsPowerService.selectWcsPowerById(id));
    }

    /**
     * 新增电能统计
     */
    @PreAuthorize("@ss.hasPermi('system:power:add')")
    @Log(title = "电能统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WcsPower wcsPower)
    {
        return toAjax(wcsPowerService.insertWcsPower(wcsPower));
    }

    /**
     * 修改电能统计
     */
    @PreAuthorize("@ss.hasPermi('system:power:edit')")
    @Log(title = "电能统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WcsPower wcsPower)
    {
        return toAjax(wcsPowerService.updateWcsPower(wcsPower));
    }

    /**
     * 删除电能统计
     */
    @PreAuthorize("@ss.hasPermi('system:power:remove')")
    @Log(title = "电能统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wcsPowerService.deleteWcsPowerByIds(ids));
    }
}
